package com.future.bantang.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.future.bantang.R;
import com.future.bantang.entity.SearchCategoryListEntity;
import com.future.bantang.utils.L;

/**
 * Created by zzh on 2016/1/15.
 * 搜索界面 单品 一级列表
 */
public class FraSearchSingleProductListAdapter extends AbsBaseAdapter<SearchCategoryListEntity.DataEntity>{

    private int selected=0;
    private static final String TAG = "FraSearchSingleProductListAdapter";
    private Context context;

    public FraSearchSingleProductListAdapter(Context context) {
        super(context, R.layout.fragment_search_single_product_category_list_item);
    }

    @Override
    public void bindDatas(ViewHolder viewHolder, SearchCategoryListEntity.DataEntity data) {
        ((TextView)viewHolder.getView(R.id.txt_fra_search_single_product_category_list_item)).setText(data.getName());
    }

    /**
     * 根据selected（被点击的item）的值动态的决定控件的属性
     * @param position
     * @param view
     */
    @Override
    public void disposalView(int position, View view) {
        if (position==selected) {
            view.setBackgroundResource(R.drawable.bg_search_catagory_list_item_bg);

            ViewHolder viewHolder = (ViewHolder) view.getTag();
            TextView textView = (TextView) viewHolder.getView(R.id.txt_fra_search_single_product_category_list_item);
            textView.setTextColor(0xffec5252);

        }else {
            view.setBackgroundResource(R.color.app_bg_gray_f0);

            ViewHolder viewHolder = (ViewHolder) view.getTag();
            TextView textView = (TextView) viewHolder.getView(R.id.txt_fra_search_single_product_category_list_item);
            textView.setTextColor(0xff999999);
        }
    }

    public void setSelected(int position){
        this.selected=position;
    }
}
